package com.ruoyi.webs.hzhelp.question.controller;

import java.util.List;

import com.ruoyi.webs.hzhelp.question.domain.HzHelpQuestion;
import com.ruoyi.webs.hzhelp.question.service.IHzHelpQuestionService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 问题Controller
 * 
 * @author ruoyi
 * @date 2021-10-03
 */
@Controller
@RequestMapping("/question")
public class HzHelpQuestionController extends BaseController
{
    private String prefix = "question";

    @Autowired
    private IHzHelpQuestionService hzHelpQuestionService;

    @RequiresPermissions("system:question:view")
    @GetMapping()
    public String question()
    {
        return prefix + "/question";
    }

    /**
     * 查询问题列表
     */
    @RequiresPermissions("system:question:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(HzHelpQuestion hzHelpQuestion)
    {
        startPage();
        List<HzHelpQuestion> list = hzHelpQuestionService.selectHzHelpQuestionList(hzHelpQuestion);
        return getDataTable(list);
    }

    /**
     * 导出问题列表
     */
    @RequiresPermissions("system:question:export")
    @Log(title = "问题", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(HzHelpQuestion hzHelpQuestion)
    {
        List<HzHelpQuestion> list = hzHelpQuestionService.selectHzHelpQuestionList(hzHelpQuestion);
        ExcelUtil<HzHelpQuestion> util = new ExcelUtil<HzHelpQuestion>(HzHelpQuestion.class);
        return util.exportExcel(list, "问题数据");
    }

    /**
     * 新增问题
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存问题
     */
    @RequiresPermissions("system:question:add")
    @Log(title = "问题", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(HzHelpQuestion hzHelpQuestion)
    {
        return toAjax(hzHelpQuestionService.insertHzHelpQuestion(hzHelpQuestion));
    }

    /**
     * 修改问题
     */
    @GetMapping("/edit/{ID}")
    public String edit(@PathVariable("ID") String ID, ModelMap mmap)
    {
        HzHelpQuestion hzHelpQuestion = hzHelpQuestionService.selectHzHelpQuestionByID(ID);
        mmap.put("hzHelpQuestion", hzHelpQuestion);
        return prefix + "/edit";
    }

    /**
     * 修改保存问题
     */
    @RequiresPermissions("system:question:edit")
    @Log(title = "问题", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(HzHelpQuestion hzHelpQuestion)
    {
        return toAjax(hzHelpQuestionService.updateHzHelpQuestion(hzHelpQuestion));
    }

    /**
     * 删除问题
     */
    @RequiresPermissions("system:question:remove")
    @Log(title = "问题", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(hzHelpQuestionService.deleteHzHelpQuestionByIDs(ids));
    }
}
